<template>
  <div class="contentTable" v-loading="loading">
    <div class="contentTableTop">
      <div class="contentTableTitle">公司</div>
    </div>
    <div class="positionList-box" v-if="positionList.length">
      <el-scrollbar style="height: 100%">
        <div
          v-for="item in positionList"
          :key="item.positionId"
          class="item"
          @mouseenter="handleMouseFloat(item)"
          @mouseleave="handleMouseFloat(item)"
        >
          <div class="item-info">
            <div class="item-info-text">
              <div class="item-info-text-middle">
                <div class="item-info-text-middle-logo">
                  <img class="logo" :src="item.logoUrl || company" />
                </div>
                <div class="item-info-text-middle-info">
                  <div class="name" @click="toCompanyDetail(item)">
                    {{ item.name }}
                  </div>
                  <div class="command-box">
                    <span class="command line" v-if="item.comScaleName">{{
                      item.comScaleName
                    }}</span>
                    <span class="command" v-if="item.tradeName">{{
                      item.tradeName
                    }}</span>
                  </div>
                  <div class="tags-box">
                    <template v-for="tag in item.tags">
                      <div v-if="tag != '专精特新企业'" :key="tag" class="tag">
                        {{
                          tag == '专精特新小巨人' ? '专精特新小巨人企业' : tag
                        }}
                      </div>
                    </template>
                  </div>
                </div>
              </div>
            </div>
            <div class="item-info-btn">
              <div class="title-num">
                <div class="num-item">
                  <span class="num">{{ item.jobs || '-' }}</span>
                  <span class="title">在招岗位</span>
                </div>
                <div class="num-item">
                  <span class="num">{{
                    typeof item.recruit == 'number' ? item.recruit : '-'
                  }}</span>
                  <span class="title">招聘人员</span>
                </div>
              </div>
              <div class="btn-box" v-show="item.showBtn">
                <div class="plain" @click.stop="handleCancelCollect(item)">
                  取消收藏
                </div>
              </div>
            </div>
          </div>
          <div class="item-contact">
            <div class="item-contact-desc text spot">
              {{ item.locationRegionDetail || '-' }}
            </div>
            <div class="item-contact-desc text task">
              {{ item.introduce || '-' }}
            </div>
          </div>
        </div>
      </el-scrollbar>
    </div>
    <el-empty class="empty" description="暂无收藏内容" v-else></el-empty>
    <div class="pager" v-show="pData.total > 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pData.currentPage"
        :page-sizes="pData.pageSizes"
        :page-size="pData.pageSize"
        :layout="pData.layout"
        :total="pData.total"
        background
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { tagsEnum } from '@/utils/jobFilterData.js';
import { collectJob, getCollectionCompany } from '@/api/job-detail';
import avatar from '@/assets/images/png/avatar_default.png';
import company from '@/assets/images/png/company.png';
import pagination from '@/mixin/pagination';
export default {
  name: 'careerTable',
  mixins: [pagination],
  components: {},
  data() {
    return {
      avatar,
      company,
      positionList: [],
      loading: false
    };
  },
  created() {
    this.getData();
  },
  methods: {
    handleCancelCollect(item) {
      this.$confirm('确定取消收藏吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.handleCollection(item);
        })
        .catch(() => {});
    },
    handleCollection(item) {
      const params = {
        dataId: item.id, // TODO:
        dataType: '11',
        action: '0' // 1 收藏 0 取消收藏
      };
      collectJob(params).then((res) => {
        if (res.code == 200) {
          this.$message.success('已取消收藏');
          this.getData();
        } else {
          this.$message.error('取消收藏失败');
        }
      });
    },
    toCompanyDetail(item) {
      let path;
      if (item.companyId) {
        path = `/company-detail?companyId=${item.companyId}`;
      } else {
        path = `/company-detail?comId=${item.id}&isShowQRCode=false`;
      }
      let routeData = this.$router.resolve({ path });
      window.open(routeData.href, '_blank');
    },
    handleMouseFloat(item) {
      item.showBtn = !item.showBtn;
    },
    getData() {
      this.loading = true;
      const params = {
        pageNo: this.pData.currentPage,
        pageSize: this.pData.pageSize
      };
      getCollectionCompany(params)
        .then((res) => {
          if (res.code == 200) {
            res.data.forEach((item) => {
              item.showBtn = false;
              if (item.__tags && item.__tags.length > 0) {
                const tags = [];
                item.__tags.forEach((tag) => {
                  if (tagsEnum.includes(tag)) {
                    tags.push(tag);
                  }
                });
                item.tags = tags;
              }
            });
            this.positionList = res.data;
            this.pData.total = res.pageparam.sums;
          } else {
            console.log(res);
          }
        })
        .catch((e) => {
          console.log(e);
        })
        .finally(() => {
          this.loading = false;
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.qr-code-popover {
  .qr-code-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: #333333;
    .qr-code {
      width: 148px;
      height: 148px;
      margin-bottom: 14px;
    }
  }
}
.contentTable {
  flex: 1;
  padding: 24px 0 24px 0;
  .contentTableTop {
    display: flex;
    align-items: center;
    padding-left: 24px;
    .contentTableTitle {
      font-family: PingFang-SC, PingFang-SC;
      font-weight: bold;
      font-size: 20px;
      color: #333333;
      line-height: 20px;
      text-align: left;
      font-style: normal;
      margin-right: 32px;
    }
  }
  .positionList-box {
    // height: 72vh;
    height: calc(100vh - 260px);
    .item {
      margin: 0 24px 15px 24px;
      background: #ffffff;
      border-radius: 8px;
      border: 1px solid #e4e5e7;
      &:first-child {
        margin-top: 15px;
      }
      .command-box {
        display: flex;
        align-items: center;
        .command {
          font-family: PingFangSC, PingFang SC;
          font-size: 13px;
          color: #a2a5b3;
          padding: 0 11px;
          &:first-child {
            padding-left: 0;
          }
        }
        .line {
          position: relative;
          &:after {
            content: '';
            position: absolute;
            top: 50%;
            right: 0;
            width: 1px;
            height: 11px;
            background: #e5e6eb;
            transform: translateY(-50%);
          }
        }
      }
      .tags-box {
        margin-top: 7px;
        display: flex;
        .tag {
          padding: 2px 11px;
          border-radius: 3px;
          background-color: #ecf0f9;
          font-size: 12px;
          color: #707c8f;
          margin-right: 6px;
        }
      }
      &:last-child {
        margin-bottom: 16px;
      }
      &:hover {
        box-shadow: 0px 2px 15px 4px rgba(73, 159, 217, 0.25);
      }
      &-info {
        display: flex;
        padding: 16px 14px;
        position: relative;
        &-text {
          flex: 1;
          display: flex;
          &-middle {
            // margin-left: 100px;
            display: flex;
            align-items: center;
            &-logo {
              width: 48px;
              height: 48px;
              padding: 3px;
              background: #ffffff;
              border-radius: 2px;
              border: 1px solid #e1e4ed;
              margin-right: 25px;
              display: flex;
              justify-content: center;
              align-items: center;
              .logo {
                width: 40px;
                height: auto;
              }
            }
            &-info {
              .name {
                margin-bottom: 8px;
                font-weight: bolder;
                font-size: 16px;
                color: #222222;
                cursor: pointer;
              }
            }
          }
        }

        &-btn {
          width: 320px;
          display: flex;
          justify-content: flex-end;
          .title-num {
            margin-left: auto;
            margin-right: 24px;
            display: flex;
            position: absolute;
            top: 16px;
            right: 128px;
            .num-item {
              color: #333;
              margin-left: 36px;
              .num {
                font-family: D-DIN-PRO-800-ExtraBold;
                font-size: 30px;
                margin-right: 6px;
              }
            }
          }
          .btn-box {
            display: flex;
          }
          .normal {
            font-family: PingFang-SC, PingFang-SC;
            font-size: 16px;
            color: #ffffff;
            width: 140px;
            text-align: center;
            border-radius: 8px;
            background: #4880ff;
            margin-right: 12px;
            height: 36px;
            line-height: 36px;
            cursor: pointer;
          }
          .plain {
            font-family: PingFang-SC, PingFang-SC;
            font-size: 16px;
            width: 104px;
            text-align: center;
            height: 36px;
            line-height: 36px;
            color: #4880ff;
            padding: 0 19px;
            border-radius: 8px;
            background: #fff;
            border: 1px solid #4880ff;
            cursor: pointer;
          }
        }
      }
      &-contact {
        display: flex;
        align-items: center;
        padding: 11px 16px;
        background: linear-gradient(
          276deg,
          rgba(218, 240, 247, 0.1) 0%,
          rgba(230, 240, 255, 0.3) 100%
        );
        &-info {
          display: flex;
          align-items: center;
          flex-grow: 0;
          .avatar {
            width: 25px;
            height: 25px;
            border: 2px solid #ffffff;
            border-radius: 50%;
            margin-right: 8px;
          }
          .time {
            margin-left: 8px;
          }
        }
        .text {
          font-family: PingFangSC, PingFang SC;
          font-size: 14px;
          color: #9cabb7;
        }
        .spot {
          flex-grow: 0;
        }
        .task {
          margin-left: 72px;
          flex: 1;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          width: 0; // 一定要设置,不然会导致文字溢出
        }
      }
    }
  }
  .pager {
    display: flex;
    justify-content: flex-end;
  }

  ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #0b6eff;
  }
}
</style>
